//------------------------------------------------------------------------------
//此代码由工具生成
//请使用partial类进行扩展,避免修改被覆盖
//------------------------------------------------------------------------------
using System;
using System.Text;
using System.Collections.Generic;
namespace XKPlatform.DataModels
{
    public partial class SysUserRoleDao
    {
        public static List<SysUserRoleModel> GetSysUserRoleModelList(int pageIndex,int pageSize,string whereSql,Dictionary<string,object> paramMap, string orderByField,int orderByType,out int totalCount)
        {
            var list = new List<SysUserRoleModel>();
            using (var conn = DbHelper.OpenConn())
            {
                var sql = "select * from SysUserRole where 1 = 1 " + whereSql;
                if (orderByType == 1)
                {
                    sql += string.Format(" Order by {0} asc Offset {1} Row Fetch Next {2} Rows Only; ", orderByField, (pageIndex - 1) * pageSize, pageSize);
                }
                else
                {
                    sql += string.Format(" Order by {0} desc Offset {1} Row Fetch Next {2} Rows Only; ", orderByField, (pageIndex - 1) * pageSize, pageSize);
                }
                conn.ExecuteReader(sql, paramMap, (rdr) =>
                {
                    var item = new SysUserRoleModel();
                    item.ID = rdr["ID"].ToString();
                    item.roleId = rdr["roleId"].ToString();
                    item.role = rdr["role"].ToString();
                    item.ApiName = rdr["ApiName"].ToString();
                    item.ModifiedBy = rdr["ModifiedBy"].ToString();
                    item.RecordStatus = rdr["RecordStatus"].ToString();
                    item.ModifiedOn = rdr["ModifiedOn"].ToString();
                    list.Add(item);
                });
                sql = "select count(1) from SysUserRole where 1 = 1 " + whereSql;
                totalCount = (int)conn.ExecuteScalar(sql, paramMap);
                return list;
            }
        }
        public static List<SysUserRoleModel> GetSysUserRoleModelList(string whereSql,Dictionary<string,object> paramMap)
        {
            var list = new List<SysUserRoleModel>();
            using (var conn = DbHelper.OpenConn())
            {
                var sql = "select * from SysUserRole where 1 = 1 " + whereSql;
                conn.ExecuteReader(sql, paramMap, (rdr) =>
                {
                    var item = new SysUserRoleModel();
                    item.ID = rdr["ID"].ToString();
                    item.roleId = rdr["roleId"].ToString();
                    item.role = rdr["role"].ToString();
                    item.ApiName = rdr["ApiName"].ToString();
                    item.ModifiedBy = rdr["ModifiedBy"].ToString();
                    item.RecordStatus = rdr["RecordStatus"].ToString();
                    item.ModifiedOn = rdr["ModifiedOn"].ToString();
                    list.Add(item);
                });
                return list;
            }
        }
        public static List<SysUserRoleModel> GetSysUserRoleModelList()
        {
            var list = new List<SysUserRoleModel>();
            using (var conn = DbHelper.OpenConn())
            {
                conn.ExecuteReader("select * from SysUserRole", null,(rdr)=>
                {
                    var item = new SysUserRoleModel();
                    item.ID = rdr["ID"].ToString();
                    item.roleId = rdr["roleId"].ToString();
                    item.role = rdr["role"].ToString();
                    item.ApiName = rdr["ApiName"].ToString();
                    item.ModifiedBy = rdr["ModifiedBy"].ToString();
                    item.RecordStatus = rdr["RecordStatus"].ToString();
                    item.ModifiedOn = rdr["ModifiedOn"].ToString();
                    list.Add(item);
                });
                return list;
            }
        }
        public static SysUserRoleModel GetSingleSysUserRoleModel(string whereSql,Dictionary<string,object> paramMap)
        {
            SysUserRoleModel item = null;
            using (var conn = DbHelper.OpenConn())
            {
                var sql = "select * from SysUserRole where 1 = 1 " + whereSql;
                conn.ExecuteReader(sql, paramMap,(rdr)=>
                {
                    item = new SysUserRoleModel();
                    item.ID = rdr["ID"].ToString();
                    item.roleId = rdr["roleId"].ToString();
                    item.role = rdr["role"].ToString();
                    item.ApiName = rdr["ApiName"].ToString();
                    item.ModifiedBy = rdr["ModifiedBy"].ToString();
                    item.RecordStatus = rdr["RecordStatus"].ToString();
                    item.ModifiedOn = rdr["ModifiedOn"].ToString();
                });
                return item;
            }
        }
        public static SysUserRoleModel GetSingleSysUserRoleModel(string key,string value)
        {
            SysUserRoleModel item = null;
            using (var conn = DbHelper.OpenConn())
            {
                var sql = "select * from SysUserRole where 1=1 ";
                sql += string.Format(" and {0}=@{0}",key);
                var paramMap = new Dictionary<string, object>()  {{string.Format("@{0}",key), value } };
                conn.ExecuteReader(sql, paramMap,(rdr)=>
                {
                    item = new SysUserRoleModel();
                    item.ID = rdr["ID"].ToString();
                    item.roleId = rdr["roleId"].ToString();
                    item.role = rdr["role"].ToString();
                    item.ApiName = rdr["ApiName"].ToString();
                    item.ModifiedBy = rdr["ModifiedBy"].ToString();
                    item.RecordStatus = rdr["RecordStatus"].ToString();
                    item.ModifiedOn = rdr["ModifiedOn"].ToString();
                });
                return item;
            }
        }
        public static int InsertSysUserRoleModel(SysUserRoleModel item)
        {
            using (var conn = DbHelper.OpenConn())
            {
                var sql = "INSERT SysUserRole(ID,roleId,role,ApiName,ModifiedBy,RecordStatus,ModifiedOn) Values(@ID,@roleId,@role,@ApiName,@ModifiedBy,@RecordStatus,@ModifiedOn)"; 
                var paramMap = new Dictionary<string, object>()  {
                    { "@ID", item.ID },
                    { "@roleId", item.roleId },
                    { "@role", item.role },
                    { "@ApiName", item.ApiName },
                    { "@ModifiedBy", item.ModifiedBy },
                    { "@RecordStatus", item.RecordStatus },
                    { "@ModifiedOn", item.ModifiedOn },
                };
                return conn.ExecuteNonQuery(sql, paramMap);
            }
        }
        public static int UpdateSysUserRoleModel(SysUserRoleModel item, string whereSql)
        {
            using (var conn = DbHelper.OpenConn())
            {
                var sql = "UPDATE SysUserRole set ID=@ID,roleId=@roleId,role=@role,ApiName=@ApiName,ModifiedBy=@ModifiedBy,RecordStatus=@RecordStatus,ModifiedOn=@ModifiedOn where   1 = 1 " + whereSql; 
                var paramMap = new Dictionary<string, object>()  {
                    { "@ID", item.ID },
                    { "@roleId", item.roleId },
                    { "@role", item.role },
                    { "@ApiName", item.ApiName },
                    { "@ModifiedBy", item.ModifiedBy },
                    { "@RecordStatus", item.RecordStatus },
                    { "@ModifiedOn", item.ModifiedOn },
                };
                return conn.ExecuteNonQuery(sql, paramMap);
            }
        }
        public static int DeleteSysUserRoleModel(string whereSql,Dictionary<string,object> paramMap)
        {
            using (var conn = DbHelper.OpenConn())
            {
                var sql = "Delete from SysUserRole where 1 = 1 " + whereSql;
                return conn.ExecuteNonQuery(sql, paramMap);
            }
        }
    }
}
